package cn.xumaoyang.org.service.impl;

import cn.xumaoyang.basic.exception.BusinessException;
import cn.xumaoyang.basic.query.BaseQuery;
import cn.xumaoyang.basic.service.impl.BaseServiceImpl;
import cn.xumaoyang.basic.util.PageList;
import cn.xumaoyang.org.domain.Employee;
import cn.xumaoyang.org.domain.Shop;
import cn.xumaoyang.org.mapper.EmployeeMapper;
import cn.xumaoyang.org.mapper.ShopMapper;
import cn.xumaoyang.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ShopServiceImpl extends BaseServiceImpl<Shop> implements IShopService {

    @Autowired
    private ShopMapper shopMapper;

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void settledIn(Shop shop) {
        //首先获取前传传来的admin，是Employee类型的接收到全部，
        Employee admin = shop.getAdmin();
        //把获取到对象的账户名传递到mapper进行数据库比较
        Employee employee = employeeMapper.loadByUser(admin);
        //判断
        if(employee != null){
        throw new BusinessException("用户已经存在，请重新输入");
        }else {
            //不存在重复数据则通过验证进行注册。
            employeeMapper.add(admin);
            //并且获取到shop对象的数据保存到数据库0。
            shopMapper.add(shop);
            //管理员E关联到S店铺id
            admin.setShop_id(shop.getId());
            //再修改掉Employee里的Shop_id
            employeeMapper.update(admin);
        }

    }
}
